package cn.t.constants;


import cn.t.core.enums.base.CommonEnum;
import cn.t.core.enums.base.CommonError;
import cn.t.core.exception.BaseError;
import cn.t.core.exception.BizException;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author l
 */

@Getter
@AllArgsConstructor
public enum ResponseError implements BaseError, CommonEnum<Integer, String> {
    PARAM_NOT_FOUND(900000, "参数为空 %s"),
    DEVICE_NOT_FOUND(900001, "设备信息不存在:%s"),
    USER_DEVICE_NOT_FOUND(900002, "用户设备权限为空！"),

    OPTION_DATA_NOT_FOUND(900003, "操作数据为空，数据类型为:%s"),

    SKU_NOT_EXIST(900004, "sku 不存在 %s"),
    OPTION_DATA_RESTRICTION(900005, "操作数据权限错误！"),
    ORDER_NOT_EXIST(900006, "订单不存在 %s！"),
    ORDER_DELETE_FAILED(900007, "订单删除失败！"),
    ORDER_GOODS_NOT_FOUND(900008, "订单详情数据为空！"),
    ORDER_UPDATE_FAILED(900009, "订单修改失败！"),
    ORDER_STATUS_FAILED(900010, "订单状态不允许操作!,当前状态为 ：%s"),
    ORDER_ERRCARWAY_NOT_FOUND(900011, "异常行信息不存在！货道号为 %s"),
    ORDER_ERRCARWAY_ERR(900012, "货道信息异常"),
    ORDER_TO_NORMAL_FAILED(900013, "异常单转订单失败"),
    WORK_LINE_FAILED(900014, "工单数据异常！"),
    LOGIN_ERR(900015, "登录异常！"),
    USER_NOT_FOUND(900016, "卡号异常！ %s"),
    TRANSFER_STATUS_ERR(900017, "异常单转单状态异常 !,当前订单状态状态 ：%s ， 转单状态： %s"),
    OVER_PICKUP_FAILED(900018, "超领数据新增异常！"),
    EXCEL_EMPTY(900019, "没有可导出的数据！"),
    EXCEL_EXPORT_ERR(900020, "导出的数据！"),
    USER_ROLE_ERR(900021, "用户设备或sku权限异常！"),
    SKU_EXIST(900022, "sku 已存在 %s"),
    DATA_CONVERT_ERR(900023, "参数转换异常"),
    CATEGORY_EXIST(900024, "商品类别 已存在 %s"),
    CATEGORY_NOT_EXIST(900025, "商品类别 不存在 %s"),
     CRM_CUSTOMER_ERR(900026, "调用CRM查询接口返回失败"),
     DATA_ERR(900027, "数据异常！"),
     CRM_CONTACT_ERR(900028, "客户联系人信息异常！"),
     CRM_ERR(900029, "客户信息异常！"),
     OMS_ERR(900030, "oms请求操作异常！"),
    PRICE_NOT_ERR(900031, "价格异常，请联系管理员！"),
    DATA_SYNC_ERR(900032, "没有数据可以同步！"),
    DATA_NOTFOUND_ERR(900033, "没有数据可以同步！"),
    RS_DATA_NOTFOUND_ERR(900034, "补货单数据不存在！"),
    OPEN_ORDER_ERR(900037, "您当前有设备领用未结束,设备编号:%s"),
    USER_STATUS_ERR(900035, "用户已锁定！"),
    DEVICE_DATA_ERR(900036, "该订单已处理！"),
    ;
    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;

    public static ResponseError getByCode(Integer source) {
        for (ResponseError value : ResponseError.values()) {
            if (value.code.equals(source)) {
                return value;
            }
        }

        throw new BizException(CommonError.ILLEGAL_PARAMETER);
    }
}
